#! /bin/bash
# 获取音量

update() {
    icon_color="^c#442266^^b#7879560x88^"
    text_color="^c#442266^^b#7879560x99^"

    check_zh=`echo $LANG|grep 'zh_CN.UTF-8'|wc -l`
    check_en=`echo $LANG|grep 'en_US.UTF-8'|wc -l`
    if [ $check_zh -eq 1 ]; then
	    #echo "zh_CN"
        volunmuted=$(pactl list sinks | grep 静音 | grep '否')
        vol_text=$(pactl list sinks | grep front | tail -1 | awk '{print $4}' | cut -d'%' -f1)
		#echo -e "$volunmuted \n $vol_text"
        #echo "zh --- end"
    elif [ $check_en -eq 1 ];then
	    #echo "en_US"
        sink=$(pactl info | grep 'Default Sink' | awk '{print $3}')
        volunmuted=$(pactl list sinks | grep $sink -A 6 | sed -n '7p' | grep 'Mute: no')
        vol_text=$(pactl list sinks | grep $sink -A 7 | sed -n '8p' | awk '{printf int($5)}')
		#echo -e "$volunmuted \n $vol_text"
        #echo "en --- end"
    fi

    if [ ! "$volunmuted" ];      then vol_text="--"; vol_icon="ﱝ";
    elif [ "$vol_text" -eq 0 ];  then vol_text="00"; vol_icon="婢";
    elif [ "$vol_text" -lt 10 ]; then vol_icon="奔"; vol_text=0$vol_text;
    elif [ "$vol_text" -le 50 ]; then vol_icon="奔";
    else vol_icon="墳"; fi

    icon="$vol_icon"
    text="$vol_text"

    echo "$icon_color $icon $text_color$text"
}

update
